<?php

namespace JLPay\Models\Trans\B2c;

use JLPay\Models\BaseResponse;

/**
 * 微支付预授权响应
 */
class MicroPayPreAuthResponse extends BaseResponse
{
    protected ?string $status = null;  // 状态 1：待确认 2：成功 3：失败
    protected ?string $mchId = null;  // 商户号
    protected ?string $termNo = null;  // 终端号
    protected ?string $deviceInfo = null;  // 终端设备号
    protected ?string $guaranteeAuthCode = null;  // 授权码
    protected ?string $transactionId = null;  // 平台订单号
    protected ?string $outTradeNo = null;  // 外部订单号
    protected ?string $chnTransactionId = null;  // 渠道订单号
    protected ?string $totalFee = null;  // 交易金额
    protected ?string $orderTime = null;  // 订单时间
    protected ?string $transTime = null;  // 交易时间
    protected ?string $finnalAmount = null;  // 实际付款金额
    protected ?string $discountAmount = null;  // 优惠总金额
    protected ?string $discountName = null;  // 优惠活动名称
    protected ?array $couponInfo = null;  // 优惠信息
    protected ?string $payType = null;  // 交易类型
    protected ?string $subOpenid = null;  // 用户openid

    /**
     * 构造函数
     *
     * @param array|null $responseArray 响应数组
     */
    public function __construct(?array $responseArray = null)
    {
        parent::__construct($responseArray ?? []);
        
        if ($responseArray) {
            $this->status = $responseArray['status'] ?? null;
            $this->mchId = $responseArray['mch_id'] ?? null;
            $this->termNo = $responseArray['term_no'] ?? null;
            $this->deviceInfo = $responseArray['device_info'] ?? null;
            $this->guaranteeAuthCode = $responseArray['guarantee_auth_code'] ?? null;
            $this->transactionId = $responseArray['transaction_id'] ?? null;
            $this->outTradeNo = $responseArray['out_trade_no'] ?? null;
            $this->chnTransactionId = $responseArray['chn_transaction_id'] ?? null;
            $this->totalFee = $responseArray['total_fee'] ?? null;
            $this->orderTime = $responseArray['order_time'] ?? null;
            $this->transTime = $responseArray['trans_time'] ?? null;
            $this->finnalAmount = $responseArray['finnal_amount'] ?? null;
            $this->discountAmount = $responseArray['discount_amount'] ?? null;
            $this->discountName = $responseArray['discount_name'] ?? null;
            $this->couponInfo = $responseArray['coupon_info'] ?? null;
            $this->payType = $responseArray['pay_type'] ?? null;
            $this->subOpenid = $responseArray['sub_openid'] ?? null;
        }
    }

    // getter方法
    public function getStatus(): ?string { return $this->status; }
    public function getMchId(): ?string { return $this->mchId; }
    public function getTermNo(): ?string { return $this->termNo; }
    public function getDeviceInfo(): ?string { return $this->deviceInfo; }
    public function getGuaranteeAuthCode(): ?string { return $this->guaranteeAuthCode; }
    public function getTransactionId(): ?string { return $this->transactionId; }
    public function getOutTradeNo(): ?string { return $this->outTradeNo; }
    public function getChnTransactionId(): ?string { return $this->chnTransactionId; }
    public function getTotalFee(): ?string { return $this->totalFee; }
    public function getOrderTime(): ?string { return $this->orderTime; }
    public function getTransTime(): ?string { return $this->transTime; }
    public function getFinnalAmount(): ?string { return $this->finnalAmount; }
    public function getDiscountAmount(): ?string { return $this->discountAmount; }
    public function getDiscountName(): ?string { return $this->discountName; }
    public function getCouponInfo(): ?array { return $this->couponInfo; }
    public function getPayType(): ?string { return $this->payType; }
    public function getSubOpenid(): ?string { return $this->subOpenid; }

    /**
     * 转换为数组
     *
     * @return array
     */
    public function toArray(): array
    {
        $data = parent::toArray();
        $data['status'] = $this->status;
        $data['mch_id'] = $this->mchId;
        $data['term_no'] = $this->termNo;
        $data['device_info'] = $this->deviceInfo;
        $data['guarantee_auth_code'] = $this->guaranteeAuthCode;
        $data['transaction_id'] = $this->transactionId;
        $data['out_trade_no'] = $this->outTradeNo;
        $data['chn_transaction_id'] = $this->chnTransactionId;
        $data['total_fee'] = $this->totalFee;
        $data['order_time'] = $this->orderTime;
        $data['trans_time'] = $this->transTime;
        $data['finnal_amount'] = $this->finnalAmount;
        $data['discount_amount'] = $this->discountAmount;
        $data['discount_name'] = $this->discountName;
        $data['coupon_info'] = $this->couponInfo;
        $data['pay_type'] = $this->payType;
        $data['sub_openid'] = $this->subOpenid;
        return $data;
    }
} 